set more 1


use bgt_employer_firm_07_to_14.dta, clear

count

keep if inlist(year, 2007, 2010, 2012)

gen educ=edu
replace educ=maxedu if educ==.

gen edureq=(educ!=.)
	
	gen eduhs=(educ==12 & !missing(educ))
	gen edusc=((educ==13 | educ==14) &!missing(educ))
	gen edubd=(educ==16  &!missing(educ))
	gen eduma=(educ==18 &!missing(educ))
	gen eduphd=(educ==21 &!missing(educ))

gen edubdgd=.
replace edubdgd=1 if (edubd==1 | eduma==1 | eduphd==1)
replace edubdgd=0 if (edubd==0 & eduma==0 & eduphd==0)


gen exper=exp
replace exper=maxexp if exp==.

drop edu maxedu exp maxexp

gen expreq=exper!=.
	
	gen exp_0to1=(exper>0 & exper<1 & !missing(exper))
	gen exp_1to2=(exper>=1 & exper<2 &  !missing(exper))
	gen exp_2to3=(exper>=2 & exper<3 & !missing(exper))
	gen exp_3to4=(exper>=3 & exper<4 & !missing(exper))
	gen exp_4to5=(exper>=4 & exper<5 & !missing(exper))
	gen exp_5to7=(exper>=5 & exper<7 & !missing(exper))
	gen exp_7to15=(exper>=7 & exper<15 & !missing(exper))


gen exp2=.
replace exp2=1 if (exp_2to3==1 | exp_3to4==1 | exp_4to5==1 | exp_5to7==1 | exp_7to15==1)
replace exp2=0 if (exp_2to3==0 & exp_3to4==0 & exp_4to5==0 & exp_5to7==0 & exp_7to15==0)

gen exp4=.
replace exp4=1 if (exp_4to5==1 | exp_5to7==1 | exp_7to15==1)
replace exp4=0 if (exp_4to5==0 & exp_5to7==0 & exp_7to15==0)
		
drop if fips=="na"
assert length(fips)==5
drop if inlist(statefip, 11, 72, 66)
count

drop if employerid==.

drop if jobid==.

egen empjobid =group(jobid employerid)
replace empjobid=. if employerid==.
replace empjobid=. if jobid==.
egen empjobstateid=group(employerid jobid statefip)

gen occsoc_broad=substr(occsoc,1,2)
gen occsoc_minor=substr(occsoc,1,3)
gen occsoc_detailed=occsoc

destring occsoc_broad, gen(occsoc_broad2)
destring occsoc_minor, gen(occsoc_minor2)
destring occsoc_detailed, gen(occsoc_detailed2)

gen occsoc_broadgroup=2 if occsoc_broad2>=11 & occsoc_broad2<=13
replace occsoc_broadgroup=3 if occsoc_broad2>=15 & occsoc_broad2<=29
replace occsoc_broadgroup=4 if occsoc_broad2>=31 & occsoc_broad2<=39
replace occsoc_broadgroup=5 if occsoc_broad2>=41 & occsoc_broad2<=43
replace occsoc_broadgroup=6 if occsoc_broad2>=45 & occsoc_broad2<=49
replace occsoc_broadgroup=7 if occsoc_broad2>=51 & occsoc_broad2<=53
label variable occsoc_broadgroup "Groups of 2-digit SOC CODES- for HWOL data merge"

merge m:1 statefip year using ur0714.dta, keep(master match) nogen assert(2 3)
drop ne_id state
replace ur=ur/100
drop if ur==.

merge m:1 statefip year occsoc_broadgroup using sdratios.dta, keep(master match) 
tab _merge
drop _merge

egen occyear=group(occsoc_broadgroup year)
egen stateocc=group(occsoc_broadgroup statefip)

summ HWOLsupdemrate_occsoc_broad,d
gen HWOLsupdemrate_occsoc_broad2=HWOLsupdemrate_occsoc_broad
replace HWOLsupdemrate_occsoc_broad2=. if HWOLsupdemrate_occsoc_broad>r(p95) | HWOLsupdemrate_occsoc_broad<r(p5)

summ BGTsupdemrate_occsoc_broad,d
gen BGTsupdemrate_occsoc_broad2=BGTsupdemrate_occsoc_broad
replace BGTsupdemrate_occsoc_broad2=. if BGTsupdemrate_occsoc_broad>r(p95) | BGTsupdemrate_occsoc_broad<r(p5)

merge m:1 statefip year occsoc using "data_for_jobtitle_vet13_2.dta", keep(master match)

gen job=1
egen totjob=sum(job), by(occsoc statefip year)
g newweight=occshare_state* (1/totjob)


collapse (mean) occshare_state educ exper edubdgd edubd exp4 exp2 empjobid empjobstateid ur HWOLsupdemrate_occsoc_broad2 BGTsupdemrate_occsoc_broad2 (count) job (first) occsoc_minor occsoc_detailed occyear occyear2 stateocc newweight, by(employerid jobid statefip year)

duplicates tag employerid jobid statefip, gen(dup)
keep if dup


reghdfe edubdgd BGTsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe exp4 BGTsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe edubdgd BGTsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)

reghdfe exp4 BGTsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)

reghdfe edubdgd BGTsupdemrate_occsoc_broad2 [w=newweight], a(occyear empjobstateid) cluster(statefip)

reghdfe exp4 BGTsupdemrate_occsoc_broad2[w=newweight], a(occyear empjobstateid) cluster(statefip)



reghdfe edubdgd HWOLsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe exp4 HWOLsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe edubdgd HWOLsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)

reghdfe exp4 HWOLsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)


preserve 

drop if year==2010
reghdfe edubdgd BGTsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe exp4 BGTsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe edubdgd BGTsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)

reghdfe exp4 BGTsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)

restore

bys empjobstateid: gen nyear=[_N]
drop if nyear!=3

reghdfe edubdgd BGTsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe exp4 BGTsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe edubdgd BGTsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)

reghdfe exp4 BGTsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)


drop if year==2010
reghdfe edubdgd BGTsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe exp4 BGTsupdemrate_occsoc_broad2, a(occyear empjobid) cluster(statefip)

reghdfe edubdgd BGTsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)

reghdfe exp4 BGTsupdemrate_occsoc_broad2, a(occyear empjobstateid) cluster(statefip)





